package io.lkt.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.Query;
import io.lkt.modules.sys.dao.SysGzhDao;
import io.lkt.modules.sys.dao.SysGzhDao2;
import io.lkt.modules.sys.entity.SysGzh2Entity;
import io.lkt.modules.sys.entity.SysGzhEntity;
import io.lkt.modules.sys.service.SysGzhService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("sysGzhService2")
public class SysGzhServiceImpl2 extends ServiceImpl<SysGzhDao2, SysGzh2Entity> implements SysGzhService2 {
    @Autowired
    private SysGzhDao2 sysGzhDao2;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SysGzh2Entity> page = this.page(
                new Query<SysGzh2Entity>().getPage(params),
                new QueryWrapper<SysGzh2Entity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void updateFansCount(Map<String, Object> params) {
        UpdateWrapper<SysGzh2Entity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("gzh_code", params.get("gzhCode").toString());

        SysGzh2Entity sysGzh = new SysGzh2Entity();
        sysGzh.setCurrentMonthFansCount(Integer.parseInt(params.get("currentMonthFansCount").toString()));

        sysGzhDao2.update(sysGzh, updateWrapper);
    }

    @Override
    public int getCurrentMonthTarget(String gzhCode) {
        QueryWrapper<SysGzh2Entity> wrapper = new QueryWrapper<>();
        wrapper.eq("gzh_code", gzhCode);
        List<SysGzh2Entity> list = sysGzhDao2.selectList(wrapper);
        return list.get(0).getCurrentMonthFansCount();
    }

}
